var mobId, mob, stats, setupTask;
var reviveCount = -1;
var mapIds = [861000050, 861000100, 861000200, 861000300, 861000400, 861000500];
var 准备地图 = 861000000;
var eventName = "副本_外星异次元";

function init() {}

function setup(c, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var c = em.newInstance(eventName);
    for (var b = 0; b < mapIds.length; b++) {
        var d = c.setInstanceMap(mapIds[b]);
        d.resetFully();
        d.killAllMonsters(true)
    }
    c.setProperty("clear_0", 1);
    for (var b = 1; b <= 5; b++) {
        c.setProperty("clear_" + b, 0)
    }
    c.schedule("UI", 1 * 1000);
    return c
}

function UI(a) {
    if (a.getPlayers().size() == 0) {
        return
    }
    a.getPlayers().forEach(function (b) {
        if (b.getMapId() > 861000050) {
            b.getAPI().外星异次元_显示UI(1)
        }
    });
    a.schedule("UI", 3 * 1000)
}

function onPlayerRegistered(b, a) {
    var c = b.getMapInstance(0);
    a.changeMap(c, c.getPortal(0));
    b.startEventTimer(1000 * 60 * 5);
    a.getAPI().updateInfoQuest(17204, "step=1;stg=1");
    a.getAPI().updateInfoQuest(17205, "")
}

function onMonsterKilled(b, e) {
    var d = Math.floor(player.getMapId() % 1000 / 100);
    var a = em.getNumberProperty("stage" + d + "_kill") + 1;
    em.setProperty("stage" + d + "_kill", a);
    var c = d == 3 || d == 5 ? 1 : 180;
    if (a <= c) {
        b.getPlayers().forEach(function (h) {
            h.getAPI().外星异次元_击杀提示(a, c)
        })
    }
    if (a == c) {
        var f = b.getTimeLeft();
        var g = f > 4 * 60 * 1000 ? "S" : f > 3 * 60 * 1000 ? "A" : f > 2 * 60 * 1000 ? "B" : "C";
        b.getPlayers().forEach(function (h) {
            h.getAPI().fieldEffect_ScreenMsg("Visitor/Rank" + g);
            h.getAPI().fieldEffect_PlayFieldSound("Dojang/clear", 100);
            h.getAPI().setStringForQuestInfo(17204, "S" + d, g.toLocaleLowerCase());
            h.getAPI().setNumberForQuestInfo(17205, "S" + d, f * 10);
            h.getAPI().setNumberForQuestInfo(17204, "step", d + 1);
            h.getAPI().addNumberForQuestInfo(17205, "exp", f * 10)
        });
        b.setProperty("clear_" + d, 1)
    }
    return 1
}

function onMapChanged(c, b, a) {
    if (mapIds.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
}

function openNpc(c, b, d) {
    for (var a = 0; a < c.getPlayerCount(); a++) {
        c.getPlayers().get(a).getAPI().openNpc(b, d)
    }
}

function warp(d, c, a) {
    for (var b = 0; b < d.getPlayerCount(); b++) {
        d.getPlayers().get(b).getAPI().warp(c, a)
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onPlayerRevived(b, a) {
    return false
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onMonsterDamaged(b, a, d, e, c) {}

function onItemPickedUp() {};